//
//  ChooseTitleView.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/24.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "ChooseTitleView.h"
#import "chooseBtnView.h"
@interface ChooseTitleView()
@property (nonatomic,strong)NSArray *titleArr;//默认的标题
@property (nonatomic,strong)NSMutableArray *selectArr;//默认selseT
@end
@implementation ChooseTitleView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self CreatUI];
    }
    return self;
}
//创建视图
-(void)CreatUI
{
    for (int i = 0; i<self.titleArr.count; i++) {
        float x = SCREENW/3*(i%3);
        float y = 5*screenW_6+35*screenW_6*(i/3);
        chooseBtnView *btnView = [[chooseBtnView alloc]initWithFrame:CGRectMake(x, y, SCREENW/3,35*screenW_6) Title:self.titleArr[i] NomolImageV:@"circle" SelectImageV:@"circle_select" IsSelect:[self.selectArr[i] isEqualToString:@"1"]?YES:NO];
        [self addSubview:btnView];
        btnView.tag = i;
        btnView.isChoose = [self.selectArr[i] isEqualToString:@"1"]?YES:NO;
        btnView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector( btnTap:)];
        [btnView addGestureRecognizer:tap];
    }
}
//默认的标题
-(NSArray *)titleArr
{
    if (!_titleArr) {
        _titleArr = @[@"满意",
                      @"方便",
                      @"很干净",
                      @"专业",
                      @"服务好",
                      @"态度好",
                      ];
    }
    return _titleArr;
}
//默认的Select
-(NSMutableArray *)selectArr
{
    if (!_selectArr) {//0：NO 1:YES
        _selectArr = @[@"0",
                      @"0",
                      @"0",
                      @"0",
                      @"0",
                      @"0",
                      ].mutableCopy;
    }
    return _selectArr;
}
//选择按钮
-(void)btnTap:(UITapGestureRecognizer *)tap
{
    chooseBtnView *btnView = (id)tap.view;
    btnView.isChoose = !btnView.isChoose;//反选按钮
    btnView.leftImagV.image = [UIImage imageNamed:btnView.isChoose?@"circle_select":@"circle"];
    [self.selectArr replaceObjectAtIndex:tap.view.tag withObject:btnView.isChoose?@"1":@"0"];
    
}
@end
